package com.cos.ssm2.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author: COS
 * @time: 2022/6/10 10:19
 * @description:
 * 统一返回数据类型
 * T E K V
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResponseResult<T> {
    /**
     *
     * @author: COS
     * @return:
     * @time: 2022/6/10 10:19
     * @description: 返回结果代码信息
     */
    private Integer code;
    /**
     *
     * @author: COS
     * @return:
     * @time: 2022/6/10 10:20
     * @description: 返回结果的提示信息
     */
    private String msg;
    /**
     *
     * @author: COS
     * @return:
     * @time: 2022/6/10 10:22
     * @description: 返回结果的数据
     */
    private T data;
    /**
     *
     * @author: COS
     * @return:
     * @time: 2022/6/10 10:34
     * @description: 构造方法
     */
    public ResponseResult(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResponseResult(String msg, T data) {
        this.msg = msg;
        this.data = data;
    }

    public ResponseResult(Integer code, T data) {
        this.code = code;
        this.data = data;
    }
    /**
     *
     * @author: COS
     * @return:
     * @time: 2022/6/10 10:32
     * @description: 成功响应信息
     */
    public static ResponseResult createSuccess(){
        return new ResponseResult(ResultCode.SUCCESS.getCode(),ResultCode.SUCCESS.getMsg());
    }
    public static <T> ResponseResult createSuccess(T data){
        return new ResponseResult(ResultCode.SUCCESS.getCode(),ResultCode.SUCCESS.getMsg(),data);
    }
    public static <T> ResponseResult createSuccess(String msg){
        return new ResponseResult(ResultCode.SUCCESS.getCode(),msg,null);
    }
    public static <T> ResponseResult createSuccess(String msg,T data){
        return new ResponseResult(ResultCode.SUCCESS.getCode(),msg,data);
    }
    /**
     *
     * @author: COS
     * @return:  
     * @time: 2022/6/10 10:36
     * @description: 失败响应
     */
    public static ResponseResult createFail(){
        return new ResponseResult(ResultCode.FAIL.getCode(),ResultCode.FAIL.getMsg());
    }
    public static <T> ResponseResult createFail(T data){
        return new ResponseResult(ResultCode.FAIL.getCode(),ResultCode.FAIL.getMsg(),data);
    }
    public static <T> ResponseResult createFail(String msg){
        return new ResponseResult(ResultCode.FAIL.getCode(),msg,null);
    }
    public static <T> ResponseResult createFail(String msg,T data){
        return new ResponseResult(ResultCode.FAIL.getCode(),msg,data);
    }



}
